import { $C, $rp } from '@/utils/constants';

const $pos5 = $C.users.activitiesV5.position;
const $act5 = $C.users.activitiesV5.action;

export default (activity) => {
  const reActivity = {
    id: activity.id,
    version: activity.version,
    created_at: activity.created_at,
    updated_at: activity.updated_at,
  };

  const info = activity.info;
  const iPos = info.actionPosition;
  const iAct = info.actionType;

  let [desc, msg1, msg2, path, err] = [];
  // desc 描述动作，例如：创建了空间
  // msg1 发生位置，例如：宋万盛的测试空间
  // msg2 回复或评论的内容
  // path 跳往动作发生的位置

  const docsPath = `/spaces/${info.spaceID}/resources-docs/${info.productFileID}`;
  const issuesPath = `/${$rp.SPACES}/${info.spaceID}/${$rp.SPACE_ISSUES}/${info.issueID}`;
  const ctrbsPath = `/${$rp.SPACES}/${info.spaceID}/${$rp.SPACE_CONTRIBUTIONS}/${info.contributionID}`;

  switch (iPos) {
    case $pos5.spaces: // 动作发生在空间
      switch (iAct) {
        case $act5.create: // 创建动作
          desc = '创建了空间';
          msg1 = info.spaceTitle;
          path = `/${$rp.SPACES}/${info.spaceID}`;
          break;
        case 'nothing': break; // 防止eslint标记
        default: err = true;
      }
      break;
    case $pos5.docs: // 动作发生在资源
      switch (iAct) {
        case $act5.reply: // 回复动作（在资源中是评论）
          desc = '评论了资源';
          msg1 = info.productFileTitle;
          path = docsPath;
          msg2 = info.reply;
          break;
        case 'nothing': break;
        default: err = true;
      }
      break;
    case $pos5.docsCmt: // 动作发生在资源下的评论区
      switch (iAct) {
        case $act5.reply: // 回复动作
          desc = '回复了评论';
          msg1 = info.discussionContent;
          path = docsPath;
          msg2 = info.reply;
          break;
        case 'nothing': break;
        default: err = true;
      }
      break;
    case $pos5.issues: // 动作发生在问题
      msg1 = info.issueTitle;
      path = issuesPath;
      switch (iAct) {
        case $act5.create: // 创建动作
          desc = '提出了问题';
          break;
        case $act5.reply: // 回复动作（在资源中是评论）
          desc = '评论了问题';
          msg2 = info.reply;
          break;
        case 'nothing': break;
        default: err = true;
      }
      break;
    case $pos5.issuesCmt: // 动作发生在问题下的评论区
      switch (iAct) {
        case $act5.reply: // 回复动作
          desc = '回复了评论';
          msg1 = info.discussionContent;
          path = issuesPath;
          msg2 = info.reply;
          break;
        case 'nothing': break;
        default: err = true;
      }
      break;
    case $pos5.ctrbs: // 动作发生在贡献区
      msg1 = info.contributionTitle;
      path = ctrbsPath;
      switch (iAct) {
        case $act5.create: // 创建动作
          desc = '提交了贡献';
          break;
        case $act5.accept: // 接受（贡献）动作
          desc = '接受了贡献';
          break;
        case $act5.close: // 关闭（贡献）动作
          desc = '关闭了贡献';
          break;
        default: err = true;
      }
      break;
    case $pos5.ctrbC: // 贡献区的评论
      msg1 = info.contributionTitle;
      path = ctrbsPath;
      if (iAct === 'reply') {
        desc = '评论了贡献';
        msg2 = info.reply;
      }
      break;
    case $pos5.ctrbCmt: // 贡献区下评论的回复
      msg1 = info.contributionTitle;
      path = ctrbsPath;
      if (iAct === 'reply') {
        desc = '回复了评论';
        msg2 = info.reply;
      }
      break;
    case $pos5.groups: // 动作发生在群组
      switch (iAct) {
        case $act5.create:
          desc = '创建了群组';
          msg1 = info.groupTitle;
          path = `/${$rp.GROUPS}/${info.groupID}`;
          break;
        case 'nothing': break;
        default: err = true;
      }
      break;
    default: err = true;
  }

  return Object.assign(reActivity, { desc, msg1, msg2, path, err });
};
